
#line 1 "..\..\main.c" /0
 
 
 
 
 
 
#error *** WARNING C318 IN LINE 6 OF ..\..\main.c: can't open file 'main.h'
  
#line 1 "..\..\..\..\..\..\..\Keil_v5\C51\INC\stdio.h" /0






 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 typedef unsigned int size_t;
 
 
 #pragma SAVE
 #pragma REGPARMS
 extern char _getkey (void);
 extern char getchar (void);
 extern char ungetchar (char);
 extern char putchar (char);
 extern int printf   (const char *, ...);
 extern int sprintf  (char *, const char *, ...);
 extern int vprintf  (const char *, char *);
 extern int vsprintf (char *, const char *, char *);
 extern char *gets (char *, int n);
 extern int scanf (const char *, ...);
 extern int sscanf (char *, const char *, ...);
 extern int puts (const char *);
 
 #pragma RESTORE
 
 
 
#line 7 "..\..\main.c" /0
 
 
 
#error *** WARNING C318 IN LINE 9 OF ..\..\main.c: can't open file 'key.h'
 
#error *** WARNING C318 IN LINE 10 OF ..\..\main.c: can't open file 'uart.h'


 
 
 
 enum PERIPHERAL
 {
 LED = 0x80,
 DEVICE = 0xa0,
 BIT = 0xc0,
 SEG = 0xe0
 };
 


 
 
 
 bit LED0, LED1, LED2, LED3, LED4, LED5, LED6, LED7;
 
 bit Buzzer;
 
 bit Relay;
 
 uchar Dsp_Bit[16] = {0};
 
 uchar Dsp_Code[8] = {0};
 
 uint	Tick;
 
 
 
 char KeyNum;
 
 
 





 
 void Timer_2Init(void)		 
 {
 AUXR |= 0x04;		 
 T2L = 0x20;			 
 T2H = 0xD1;			 
 AUXR |= 0x10;		 
 
 IE2 |= 0x04;		 
 EA = 1;
 }
 





 
 void Timer2_Service() interrupt 12
 {
 static uchar dsp_com;
 
 
 Tick++;		
 
 
  P0=~((uchar)LED0|(uchar)LED1<<1|(uchar)LED2<<2|(uchar)LED3<<3|(uchar)LED4<<4|(uchar)LED5<<5|(uchar)LED6<<6|(uchar)LED7<<7);P2=LED;P2=0;
 
  P0=(uchar)Buzzer<<6|(uchar)Relay<<4;P2=DEVICE;P2=0;	
 
  P0=0;P2=BIT;P2=0;									 
  P0=Dsp_Code[dsp_com];P2=SEG;P2=0;		 
  P0=1 << (dsp_com);P2=BIT;P2=0;				 
 if(++dsp_com > 7)								 
 dsp_com = 0;
 }
 





 
 void Seg_Tran(void)
 {
 unsigned char i, j=0, temp;
 for (i=0; i<8; i++, j++)
 {
 switch (Dsp_Bit[j]) 
 {  
 case '0': temp = 0xc0; break;
 case '1': temp = 0xf9; break;
 
 case '2': temp = 0xa4; break;
 case '3': temp = 0xb0; break;
 
 case '4': temp = 0x99; break;
 
 case '5': temp = 0x92; break;
 case '6': temp = 0x82; break;
 
 case '7': temp = 0xf8; break;
 
 case '8': temp = 0x80; break;
 case '9': temp = 0x90; break;
 
 case 'A': temp = 0x88; break;
 case 'B': temp = 0x83; break;
 case 'C': temp = 0xc6; break;
 case 'D': temp = 0xA1; break;
 case 'E': temp = 0x86; break;
 case 'F': temp = 0x8E; break;
 case 'H': temp = 0x89; break;
 case 'L': temp = 0xC7; break;
 case 'N': temp = 0xC8; break;
 case 'P': temp = 0x8c; break;
 case 'U': temp = 0xC1; break;
 case '-': temp = 0xbf; break;
 case ' ': temp = 0xff; break;
 case '^': temp = 0xfe; break;  
 case '_': temp = 0xf7; break;  
 default: temp = 0xff;
 }
 if (Dsp_Bit[j+1] == '.')
 {
 temp = temp&0x7f;              
 j++;
 }
 Dsp_Code[i] = temp;
 }
 }





 
 void Display_Task(void)
 {
 static uchar Display_Tick;
 
 if((Tick - Display_Tick) > 500)
 {	
 Display_Tick = Tick;		
 sprintf(Dsp_Bit, "%9.2f", (float)KeyNum);
 
 }
 Seg_Tran();
 }
 





 
 void Key_Task(void)
 {
 static uint Key_Tick;							
 char Key_Value;							
 
 if((Tick - Key_Tick) > 2)
 {
 Key_Tick = Tick;
 
 Key_Value = MatKeyScan_2x4();
 switch (Key_Value)
 {
 case 4:case 5:case 6:case 7:case 8:case 9:case 10:case 11:case 12:case 13:case 14:case 15:case 16:case 17:case 18:case 19:
 KeyNum = -Key_Value;
 break;
 default:
 break;
 }			
 }
 }	
 





 
 void Data_Task(void)
 {
 static uint Data_Tick;
 
 if((Tick - Data_Tick) > 500)
 {	
 Data_Tick = Tick;
 }
 
 }
 





 
 void Logic_Task(void)
 {
 static uint Logic_Tick;
 
 if((Tick - Logic_Tick) > 500)
 {	
 Logic_Tick = Tick;
 }
 
 }
 





 
 void P_Init(void)				 
 {
  P0=0xff;P2=LED;P2=0;		 
  P0=0x00;P2=DEVICE;P2=0;	 
  P0=0x00;P2=BIT;P2=0;		 
  P0=0xff;P2=SEG;P2=0;		 
 
 Timer_2Init();
 
 }
 uint a;
 float b;


 
 void main(void)
 {
 
 
 P_Init();
 UartInit();	
 
 
 while(1)
 {
 
 
 
 
 printf("Please Enter a uint num a:\r\n");
 scanf("%bd",&a); 
 PRINT_INT(a);
 printf("Please Enter a int float b:\r\n");
 scanf("%bf",&b); 
 printf("b = %b6f\r\n", b);
 
 printf("\r\nGive me string ended with ENTER:\r\n");
 scanf("%s",uart_tx);
 printf("Last receive string:%s\r\n",uart_tx);
 }        
 }
